package pile.pay.config.alipayConfig;

import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;


@Component
@Log4j2
public class AlipaySdk {
    // 初始化SDK
    AlipayClient alipayClient;


    public AlipayClient getAlipayClient() {
        try {
            if (alipayClient == null) {
                alipayClient =  new DefaultAlipayClient(getAlipayConfig());
            }
        } catch (Exception e) {
            log.error("Alipay报错:" + e);
        }
        return alipayClient;
    }

    public AlipayConfig getAlipayConfig() {

        String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCWNlC8nOJ6bYWrawhoQR+EJStj8wMZuACaxP+FBjdZ5joyWzim/0s/UoLbkMpizHN5XnKhB5WagwrasUa8FMrvsNFw/aHwPf0wKImtilS/oYdIMNG3wQRSLN7I0aNZjoNaozzZn9WyoFUzd8KHmsqBEkoVVijD1ANvBNsNmx7qetMg7CxIZXTNe+gcYIEbVlON0NzG6SHahGkWZx3jmxrmyr1Jvy6VIAyIuDLtNWr9VL4f6HgSZBoaMlE4KZ289XuMiELQko6zZnz/YY19E4g6mDeEnD1WtxLFjtjuh+IwJVh5E/SdmZx7/HO9JiFmF1x1+qyMIaluE/8gGaAHWsoHAgMBAAECggEALip3WeClwpbSlEKLDO+m7gg2c7uGYmso1GhjV9D3Rgv6KuvaV4jy6X1EdpLjgMXxX4XlmRQpqJlJxrjhUoDZdh1T4XQyRxHmNNzgo5N2RIcyer92VRFfcJoVxoaXu7iPKlYtJ312QjYAuZa/FMpAHrcuSax3TuhkPcSyRlY8hDfOGTD1WSPL0zOwC7oOVbO+kCh/kdOxIBc7RGnBtC7Mo5HTCl4wx570Hdkga5t3P+X5grzarpAYGBSui1RJfy0fimMc1ec+KGk2uIpdHFFtY4qlMK7N26sxE8sgrJ79pvWtVJu9vG4tPb3hU87/REX88lGYeiMHeM9D2WxnPkw2YQKBgQDeZg2c0oMXZxbudOcYIs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gPaG5hTNL57bi6sP0FAYqPJODxYP4rMi9YmEV8UqY9IivXM9+NL2RPHZ473DuzLAntrrY6HNi7RH/GLE3YXaRCv8XHT1XNMbq9QRNpj4xeRTk4OqA/zLVQ3D1M93thKuLuEQlvdhgq4vvKBpmpGYTyN5/MVUY0WsE5vSQIDAQAB";

        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
        alipayConfig.setAppId("2021004150614322");
        alipayConfig.setPrivateKey(privateKey);
        alipayConfig.setFormat("json");
        alipayConfig.setAlipayPublicKey(alipayPublicKey);
        alipayConfig.setCharset("UTF-8");
        alipayConfig.setSignType("RSA2");
        return alipayConfig;
    }
}